﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MeetingVote.aspx.cs" Inherits="Meeting.Web.Admin.MeetingPre.MeetingVote" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>投票设置</title>
    <link href="../../Css/SmartWizard/smart_wizard.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
       <!--ardialog--> 
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/plugins/iframeTools.js"></script>
    <link href="../../Css/main.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <script src="../../Scripts/datagrid-detailview.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/common.js"></script>
    <script src="../../Scripts/Json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        var meetingId = request("Id");
        var CategoryId = request("CategoryId");
        $(function () {
           
            $("#MeetingName").html(unescape(request("Name")));
            InitVote();
        });
        function InitVote() { 
            $("#voteSelect").datagrid({
                url: 'MeetingOperation.ashx?method=GetSelectVote&Id=' + meetingId,
                singleSelect: true
            }); 
        }
        function SelectVote() {
            var radStr = Math.random();
            var url = "../SelectBase/SelectVote.aspx" + '?Radstr=' + radStr;
            art.dialog.open(url, {
                id: 'AddVote', title: '选择投票', width: 600, height: 390, lock: true,
                close: function () {
                    var selJson = art.dialog.data('selJson'); // 读取人员选择返回值
                    //  alert(selNodeJson);
                    if (selJson != "") {
                        try {
                            var data = JSON.parse(selJson);
                            DelAllSelectVote();
                            for (i = 0; i < data.length; i++) {
                                $('#voteSelect').datagrid('appendRow', data[i]);
                            }
                        } catch (ex) { }
                    }
                }
            }, true);
        }
         function DelAllSelectVote() {
            var rows = $('#voteSelect').datagrid('getRows');
            for (i = rows.length - 1; i >= 0; i--) {
                $('#voteSelect').datagrid('deleteRow', i);
            }
        }
        function DelSelectVote(val, row) {
            return "<a href='#' class='easyui-linkbutton' onclick=\"DelMeetingSelectVote('" + row.VoteId + "');\"  >移除</a> ";
        }
        function DelMeetingSelectVote(voteId) {
            var data = $('#voteSelect').datagrid('getData');
            var index = -1;
            for (i = 0; i < data.total; i++) {
                if (data.rows[i].VoteId == voteId) {
                    index = i;
                    break;
                }
            }
            $('#voteSelect').datagrid('deleteRow', index);
        }
        //保存投票信息
        function SaveMeetingVote() {

            var data = $('#voteSelect').datagrid('getData');
            var str = JSON.stringify(data.rows);
            var Id = meetingId;
            var postData = { Id: Id, data: str };
            //提交

            $.post("MeetingOperation.ashx?method=SaveMeetingVote", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", "保存成功");
                    //保存成功，退出当前对话框
                    art.dialog.close();
                } else {
                    $("#error").val(data.Message); $.messager.alert("提示", data.Message);
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="showView1" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td class="title">
                    会议名称:
                </td>
                <td class="td_Modify1" style="">
                    <span id="MeetingName"></span>
                </td>
            </tr>
            <tr>
                <td class="title">
                    已选投票:
                </td>
                <td class="td_Modify1" style="">
                 <a id="A3" class="easyui-linkbutton" onclick="SelectVote();">选择投票</a>
                    <table id="voteSelect" style="width: 500px; height: 230px;" singleselect="true" fitcolumns="true">
                        <thead>
                            <tr>
                                <th data-options="field:'VoteId',width:80,hidden:true">
                                    投票编号
                                </th>
                                <th data-options="field:'MeetingId',width:80,hidden:true">
                                    投票编号
                                </th>
                                <th data-options="field:'Theme',width:80">
                                    投票主题
                                </th>
                                <th data-options="field:'action',width:80,formatter:DelSelectVote">
                                </th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
             
             <tr>
                <td class="title">
                   
                </td>
                <td class="td_Modify1" style="">
                    <a href="#" class="easyui-linkbutton" onclick="SaveMeetingVote();">保存</a>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
